//
//  FSNavController.m
//  fanshu
//
//  Created by mh on 16/3/27.
//  Copyright © 2016年 FS. All rights reserved.
//

#import "FSNavController.h"

@interface FSNavController ()<UIGestureRecognizerDelegate>

@end

@implementation FSNavController
//初始化方法    设置所有一次性的设置
+ (void)initialize{
    // 设置整个项目所有item的主题样式
    UIBarButtonItem *item = [UIBarButtonItem appearance];
    //普通状态
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[NSForegroundColorAttributeName] = [UIColor whiteColor];
    [item setTitleTextAttributes:dict forState:UIControlStateNormal];
    
    //高亮状态
    NSMutableDictionary *highLightedDict = [NSMutableDictionary dictionary];
    dict[NSForegroundColorAttributeName] = [UIColor orangeColor];
    [item setTitleTextAttributes:highLightedDict forState:UIControlStateHighlighted];
    
    //不可用状态
    NSMutableDictionary *disDict = [NSMutableDictionary dictionary];
    disDict[NSForegroundColorAttributeName] = [UIColor colorWithRed:154/255.0 green:154/255.0 blue:154/255.0 alpha:1];
    [item setTitleTextAttributes:disDict forState:UIControlStateDisabled];
}
/**
 *  push控制器，更改两边的按钮
 */
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    //设置按钮
    if (self.childViewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
        
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(back) image:@"icon_tabbar_back"  highImage:nil];
        
        viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(back) image:@"icon_tabbar_white_more"  highImage:nil];
    }
    [super pushViewController:viewController animated:animated];
}
/**
 *  点击返回按钮
 */
- (void)back{
    [self popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //全屏侧滑返回手势   尝试去除警告
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self.interactivePopGestureRecognizer.delegate action:NSSelectorFromString(@"handleNavigationTransition:")];
    pan.delegate = self;
    [self.view addGestureRecognizer:pan];
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    if (self.childViewControllers.count == 1) {
        return NO;
    }
    return YES;
}

@end
